<template>
  <view class="contents" v-if="listv">
    <view
      :style="{
        color: 'rgb(173, 173, 173)',
        'text-align': 'center',
        padding: '0 30rpx',
        'margin-bottom': '40rpx',
      }"
      v-if="showAnTitle"
      >{{ anTitle }}</view
    >
    <view class="chhose_item" v-if="isShow">
      <u-tabs
        :list="list"
        lineWidth="0"
        lineColor="#f56c6c"
        :activeStyle="{
          color: '#55B877',
          height: '56rpx',
          'line-height': '56rpx',
          'text-align': 'center',
          'border-radius': '32rpx 32rpx 32rpx 32rpx',
          'font-size': '32rpx',
        }"
        :inactiveStyle="{
          height: '56rpx',
          'line-height': '56rpx',
          'text-align': 'center',
          color: '#ADADAD',
          'font-size': '32rpx',
        }"
        itemStyle="padding:0 30rpx; height: 56rpx'width: 100rpx"
        @change="change"
      >
      </u-tabs>
    </view>
    <view v-if="currentIndex < 2">
      <view
        class="card"
        v-for="(item, index) in listv.data"
        :key="index"
        @click="goDetail(item)"
      >
        <view class="card_top" v-if="my_level_id >= item.grade_auth">
          <view class="card_name">{{ item.title }}</view>
          <view class="card_icon">
            <u-icon name="arrow-right" color="#ADADAD" size="20"></u-icon>
          </view>
        </view>

        <!-- 预览样式 -->
        <view class="Preview_style" v-else @click.stop="goMember">
          该内容仅支持{{
            item.grade_auth == 1
              ? "元气驿站"
              : item.grade_auth == 2
              ? "启初梦谷"
              : item.grade_auth == 3
              ? "青空天台"
              : item.grade_auth == 4
              ? "无极云顶"
              : item.grade_auth == 5
              ? "返朴归源"
              : ""
          }}及以上行者查看
        </view>
        <!-- <view class="card_content"></view> -->
        <view class="card_bottom">
          <!-- 头像 -->
          <view class="avatar">
            <image
              class="zanImg"
              :src="item.user.avatar_url"
              @click.stop="goHome(item.user.user_id)"
            ></image>
            <view class="nick">{{ item.user.nick_name }}</view>
          </view>
          <view class="avatarRight">
            <view class="time">{{ item.create_time }}</view>
          </view>
        </view>
      </view>
    </view>

    <view v-if="currentIndex == 2">
      <view
        class="new_card"
        v-for="(item, index) in listv.data"
        :key="index"
        @click="goDetail(item)"
      >
        <view class="card_top">
          <view class="card_name">{{ item.title }}</view>
          <view class="card_icon" v-show="flag">
            <u-icon name="arrow-right" color="#ADADAD" size="20"></u-icon>
          </view>
          <view
            v-show="!flag"
            class="item_left_clickView"
            @click.stop="itemClickAble(item)"
          >
            <image
              v-if="!item.clickable"
              class="item_left_click"
              src="../static/images/my/icon_grzy_quanxuan.png"
              mode=""
            ></image>
            <image
              v-else
              class="item_left_clickable"
              src="../static/images/my/icon_grzy_xc_xuanzhong.png"
              mode=""
            ></image>
          </view>
        </view>

        <view class="card_content_box">
          <view class="card_content" :class="my_level_id < item.grade_auth ? 'card_content1' : ''">{{ item.content }}</view>
          <view
            class="card_content_box_preview"
            v-if="my_level_id < item.grade_auth"
            @click.stop="goMember"
          >
            该内容仅支持{{
              item.grade_auth == 1
                ? "元气驿站"
                : item.grade_auth == 2
                ? "启初梦谷"
                : item.grade_auth == 3
                ? "青空天台"
                : item.grade_auth == 4
                ? "无极云顶"
                : item.grade_auth == 5
                ? "返朴归源"
                : ""
            }}及以上行者查看
          </view>
        </view>

        <view class="card_bottom">
          <!-- 头像 -->
          <view class="avatar">
            <image
              class="zanImg"
              :src="item.user.avatar_url"
              @click.stop="goHome(item.user.user_id)"
            ></image>
            <view class="nick">{{ item.user.nick_name }}</view>
          </view>
          <view class="avatarRight">
            <view class="time" v-if="!displayMode">{{ item.create_time }}</view>
            <view class="time" v-else>{{
              item.status == 0
                ? "公开"
                : item.status == 1
                ? "粉丝可见"
                : "尽自己可见"
            }}</view>
          </view>
        </view>
      </view>
    </view>

    <view v-if="currentIndex == 3">
      <view
        class="card"
        v-for="(item, index) in listv.data"
        :key="index"
        @click="goPage(item)"
      >
        <view class="card_top">
          <view class="card_name">{{ item.name }}</view>
          <view class="card_icon">
            <u-icon name="arrow-right" color="#ADADAD" size="20"></u-icon>
          </view>
        </view>
        <!-- <view class="card_content"></view> -->
        <view class="card_bottom">
          <!-- 头像 -->
          <view class="avatar1">
            内容 {{ item.like_count || item.number || 0 }}
          </view>
          <view class="avatar_show" v-if="item.status == 2 && displayMode"
            >仅自己可见</view
          >
          <view class="avatar_show" v-if="item.status == 1 && displayMode"
            >粉丝可见</view
          >
          <view class="avatar_show" v-if="item.status == 0 && displayMode"
            >公开</view
          >
          <!-- <view class="avatar_show">仅自己可见</view> -->
          <!-- <view class="avatar_show">粉丝可见</view> -->
          <!-- <view class="avatar_show">公开</view> -->
        </view>
      </view>
    </view>

    <view class="bottom" v-show="!flag">
      <view class="bottom_left">
        <view @click="changeClick">
          <image
            v-if="!clickableAll"
            class="item_left_click"
            src="../static/images/my/icon_grzy_quanxuan.png"
            mode=""
          ></image>
          <image
            v-else
            class="item_left_click"
            src="../static/images/my/icon_grzy_xc_xuanzhong.png"
            mode=""
          ></image>
        </view>
        <view class="bottom_left_text">全选</view>
      </view>

      <view class="bottom_right" @click="deleteFn">删除</view>
    </view>

    <u-modal
      :show="show"
      :title="title"
      :content="content"
      confirmColor="#55B877"
      :closeOnClickOverlay="true"
      @confirm="confirm"
      @close="close"
      @cancel="cancel"
      :showCancelButton="true"
    ></u-modal>

    <view class="empty_view" v-if="listv.data && listv.data.length == 0">
      <image
        class="item_left_clickable"
        src="../static/images/my/kong.png"
        mode=""
      ></image>
      <view v-if="from == 'history'">您还没有历史记录~</view>
      <view v-else>当前没有相关数据，请查看其他分类或功能。</view>
    </view>
    <!-- 底部空间 -->
    <view style="height: 100rpx" v-if="isHome"></view>
  </view>
</template>
<script>
import storage from "@/common/storage"; // 缓存封装
export default {
  props: {
    isShow: {
      type: Boolean,
      default: true,
    },
    currentIndex: {
      type: Number,
      default: 0,
    },
    flag: {
      type: Boolean,
      default: true,
    },
    identity: {
      type: Number,
      default: 0,
    },
    familyList: {
      type: Object,
      default: () => {
        return {};
      },
    },
    moduleType: {
      type: String,
      default: "wei",
    },
    displayMode: {
      type: Boolean,
      default: false,
    },
    isHome: {
      type: Boolean,
      default: false,
    },
    isHomeShi: {
      type: Boolean,
      default: false,
    },
    type: {
      type: String,
      default: "",
    },
    from: {
      type: String,
      default: "",
    },
    showAnTitle: {
      type: Boolean,
      default: false,
    },
    my_level_id: {
      type: Number,
      default: 0,
    },
  },
  watch: {
    familyList: {
      deep: true, // 深度监听每一个属性值, 如果是对象可以深度监听
      immediate: true, // 进入页面后立即自动调用handler函数
      handler(newValue) {
        this.listv = newValue;
        if (this.listv.data) {
          for (let i = 0; i < this.listv.data.length; i++) {
            this.listv.data[i].clickable = false;
          }
        }

        // console.log(this.listv, "newList", "文心岛");
      },
    },
    isHome: {
      deep: true, // 深度监听每一个属性值, 如果是对象可以深度监听
      immediate: true, // 进入页面后立即自动调用handler函数
      handler(newValue) {
        console.log(newValue, "刷新了新值");
        if (newValue == true) {
          this.anTitle = storage.get("shanAn").jiazushu;
        } else {
          this.anTitle = storage.get("shanAn").wenxindao;
        }
      },
    },
  },
  onLoad(options) {
    // this.type = options.type;
  },
  mounted() {
    // console.log(storage.get('shanAn'),'山海暗文')
    // this.anTitle = storage.get('shanAn').jiazushu
  },
  data() {
    return {
      list: [
        {
          name: "最新",
        },
        {
          name: "按点赞",
        },
        {
          name: "按浏览",
        },
      ],
      listValue: [
        {
          title: "第一百零六章：巴蜀全貌",
          text: "《巴纳姆效应》",
          headImg: "https://cdn.uviewui.com/uview/album/1.jpg",
          name: "柳语晨",
          time: "2023年09月06日",
          clickable: false,
        },
        {
          title: "第一百零六章：巴蜀全貌",
          text: "《巴纳姆效应》",
          headImg: "https://cdn.uviewui.com/uview/album/1.jpg",
          name: "柳语晨",
          time: "2023年09月06日",
          clickable: false,
        },
        {
          title: "第一百零六章：巴蜀全貌",
          text: "《巴纳姆效应》",
          headImg: "https://cdn.uviewui.com/uview/album/1.jpg",
          name: "柳语晨",
          time: "2023年09月06日",
          clickable: false,
        },
      ],
      clickableAll: false,
      show: false,
      title: "确认删除",
      content: "确认删除选中内容？",
      listv: {},
      anTitle: "", // 山海暗文标题
      // type:''
    };
  },
  methods: {
    change(e) {
      // console.log("eeeeeee", e);
      // this.currentIndex = e.index;
      this.$emit("updateWenList", e.index);
    },
    // 跳个人主页
    goHome(user_id) {
      uni.navigateTo({
        url: `/pages/home/home?user_id=${user_id}`,
      });
    },
    // 跳会员页面
    goMember() {
      uni.navigateTo({
        url: `/pages/member/index`,
      });
    },
    goDetail(item) {
      if (this.isHome) {
        // 首页家族树跳转
        uni.navigateTo({
          url: `/pages/detail/flyDetail?detailType=jiazu&currentId=${item.id}&from=wei`,
        });
        return;
      }
      if (this.isHomeShi) {
        // 首页诗心园跳转
        uni.navigateTo({
          url: `/pages/detail/flyDetail?detailType=shi&currentId=${item.id}&from=wei`,
        });
        return;
      }
      if (this.type) {
        uni.navigateTo({
          url: `/pages/detail/flyDetail?type=my&detailType=wen&currentId=${item.id}&from=wei`,
        });
      } else {
        uni.navigateTo({
          url: `/pages/detail/flyDetail?detailType=wen&currentId=${item.id}&from=wei`,
        });
      }
    },
    goPage(item) {
      if (this.type) {
        uni.navigateTo({
          url: `/pages/detail/wenList?type=my&user_id=${item.user_id}&name=${item.name}`,
        });
      } else {
        uni.navigateTo({
          url: `/pages/detail/wenList?user_id=${item.user_id}&name=${item.name}`,
        });
      }
    },
    // 各项选择
    itemClickAble(listItem) {
      this.$forceUpdate();
      listItem.clickable = !listItem.clickable;
      let all = true;
      for (let i = 0; i < this.listv.data.length; i++) {
        if (this.listv.data[i].clickable == false) {
          all = false;
        }
      }
      if (all) {
        this.clickableAll = true;
      } else {
        this.clickableAll = false;
      }
    },
    // 全选
    changeClick() {
      this.clickableAll = !this.clickableAll;
      if (this.clickableAll) {
        for (let i = 0; i < this.listv.data.length; i++) {
          this.listv.data[i].clickable = true;
        }
      } else {
        for (let i = 0; i < this.listv.data.length; i++) {
          this.listv.data[i].clickable = false;
        }
      }
    },
    confirm() {
      let arr = [];
      let num = 0;
      for (let i = 0; i < this.listv.data.length; i++) {
        if (this.listv.data[i].clickable == true) {
          arr.push(this.listv.data[i].history_id);
          num++;
        }
      }
      // console.log(arr, "数组");
      this.deletFn(arr);
    },
    close() {
      this.show = false;
    },
    cancel() {
      this.show = false;
    },
    // 删除按钮
    deleteFn() {
      let isTrue = true;
      for (let i = 0; i < this.listv.data.length; i++) {
        // console.log(this.listv.data[i].clickable);
        if (this.listv.data[i].clickable == true) {
          isTrue = false;
        }
      }
      if (isTrue == true) {
        uni.$u.toast("您还未选择内容");
      } else {
        this.show = true;
      }
    },
    // 删除接口
    deletFn(arr) {
      if (this.moduleType == "wei") {
        // 微创删除
        this.$http
          .historyDel_his_weichuang({ ids: arr })
          .then((res) => {
            uni.$u.toast(res.message);
            this.show = false;
            setTimeout(() => {
              this.$emit("updateDataWen");
            }, 1000);
          })
          .catch((error) => {
            uni.$u.toast(error);
          });
      } else if (this.moduleType == "gong") {
        // 共创删除
        this.$http
          .historyDel_his_gongchuang({ ids: arr })
          .then((res) => {
            uni.$u.toast(res.message);
            this.show = false;
            setTimeout(() => {
              this.$emit("updateDataGongWen");
            }, 1000);
          })
          .catch((error) => {
            uni.$u.toast(error);
          });
      }
    },
  },
};
</script>
<style scoped lang="scss">
.contents {
  height: 100%;
  padding: 40rpx 0;
  .card {
    margin-left: 30rpx;
    margin-top: 32rpx;
    width: 690rpx;
    height: 200rpx;
    background: rgba(39, 39, 39, 0.5);
    border-radius: 16rpx 16rpx 16rpx 16rpx;
    .card_top {
      display: flex;
      justify-content: space-between;
      padding: 32rpx 32rpx 24rpx;
      position: relative;
      .card_name {
        font-size: 34rpx;
        font-weight: 400;
        color: #eeeeee;
      }
    }
    .Preview_style {
      width: 100%;
      height: 98rpx;
      border-radius: 16rpx;
      // margin-top: 24rpx;
      text-align: center;
      line-height: 98rpx;
      color: white;
      // background: rgba(105, 113, 151, 0.7);
    }
    .card_content {
      padding-left: 32rpx;
      width: 269rpx;
      height: 44rpx;
      font-size: 26rpx;
      font-family: PingFang SC-Medium, PingFang SC;
      font-weight: 400;
      color: #eeeeee;
      line-height: 38rpx;
    }

    .card_bottom {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 32rpx;
      .avatar {
        display: flex;
        align-items: center;
        .zanImg {
          width: 56rpx;
          height: 56rpx;
          border-radius: 28rpx;
        }
        .nick {
          font-size: 28rpx;
          margin-left: 16rpx;
          font-weight: 400;
          color: #eeeeee;
        }
      }
      .avatar1 {
        font-size: 26rpx;
        color: #adadad;
      }
      .avatar_show {
        font-size: 26rpx;
        color: #adadad;
      }
      .avatarRight {
        font-size: 28rpx;
        font-weight: 400;
        color: #adadad;
      }
    }
  }
  .new_card {
    margin-left: 30rpx;
    margin-top: 32rpx;
    width: 690rpx;
    // height: 268rpx;
    background: rgba(39, 39, 39, 0.5);
    border-radius: 16rpx 16rpx 16rpx 16rpx;

    .card_top {
      display: flex;
      justify-content: space-between;
      padding: 32rpx 32rpx 24rpx;
      position: relative;
      .card_name {
        font-size: 32rpx;
        font-weight: 400;
        color: #eeeeee;
      }
      .item_left_clickView {
        margin-right: 32rpx;
        position: absolute;
        right: 0;
        top: 0;
        margin-top: 32rpx;
        .item_left_click {
          width: 40rpx;
          height: 40rpx;
        }
        .item_left_clickable {
          width: 40rpx;
          height: 40rpx;
        }
      }
    }
    .card_content {
      padding-left: 32rpx;
      width: 269rpx;
      // height: 44rpx;
      font-size: 26rpx;
      font-family: PingFang SC-Medium, PingFang SC;
      font-weight: 400;
      color: #eeeeee;
      line-height: 38rpx;
      overflow: hidden;
      -webkit-line-clamp: 3;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-box-orient: vertical;
    }
    .card_bottom {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 32rpx;
      .avatar {
        display: flex;
        align-items: center;
        .zanImg {
          width: 56rpx;
          height: 56rpx;
          border-radius: 28rpx;
        }
        .nick {
          font-size: 24rpx;
          margin-left: 16rpx;
          font-weight: 400;
          color: #eeeeee;
        }
      }
      .avatarRight {
        font-size: 24rpx;
        font-weight: 400;
        color: #adadad;
      }
    }

    .card_content_box {
      position: relative;
    }
    .card_content_box_preview {
      color: #eeeeee;
      padding-top: 30rpx;
      box-sizing: border-box;
      position: absolute;
      top: 0;
      background: linear-gradient(
        360deg,
        rgba(48, 53, 77, 1) 50%,
        rgba(49, 57, 79, 0) 100%
      );
      text-align: center;
      width: 100%;
      height: 100%;
    }
    .card_content1 {
      height: 114rpx;
    }
  }

  .bottom {
    width: 100%;
    height: 112rpx;
    background: #272727;
    position: fixed;
    bottom: 0;
    left: 0;
    padding: 16rpx 30rpx;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .bottom_left {
      display: flex;
      align-items: center;
      .item_left_click {
        width: 40rpx;
        height: 40rpx;
      }
      .bottom_left_text {
        margin-left: 16rpx;
        color: #eeeeee;
        font-size: 30rpx;
      }
    }

    .bottom_right {
      width: 250rpx;
      height: 80rpx;
      background: #ee6060;
      border-radius: 48rpx;
      text-align: center;
      line-height: 80rpx;
      font-size: 30rpx;
      color: #eeeeee;
    }
  }

  /deep/.u-modal__content__text {
    text-align: center;
  }
  .empty_view {
    margin-top: 300rpx;
    image {
      margin: 0 auto;
      width: 410rpx;
      height: 410rpx;
    }
    view {
      font-size: 30rpx;
      color: #d8d8d8;
      text-align: center;
    }
  }
  .chhose_item {
    // margin-top: 40rpx;
  }
}
</style>
